package com.webchat.ugc;

import com.webchat.common.util.SpringContextUtil;
import com.webchat.rmi.annotation.EnableRpcPermissionFilter;
import com.webchat.rmi.annotation.EnableRpcPermissionInterceptor;
import com.webchat.ugc.messaegqueue.consumer.redis.MallProductOrderTimeoutDelayRedisMQConsumer;
import com.webchat.ugc.messaegqueue.consumer.redis.MallProductOrderTimeoutRedisQueueConsumer;
import com.webchat.ugc.messaegqueue.consumer.redis.MallUserCartRedisQueueConsumer;
import com.webchat.ugc.messaegqueue.consumer.redis.MomentPublishRedisMQConsumer;
import com.webchat.ugc.messaegqueue.consumer.redis.PersistentMessageRedisMQConsumer;
import com.webchat.ugc.messaegqueue.consumer.redis.RefreshChattingRedisMQConsumer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@EnableDiscoveryClient
@ComponentScan("com.webchat")
@EnableFeignClients("com.webchat.rmi")
@EnableRpcPermissionInterceptor
@EnableRpcPermissionFilter
public class WebchatUGCApplication {

    public static void main(String[] args) {

        SpringApplication.run(WebchatUGCApplication.class, args);

        /**
         * 启动Redis MQ
         */
        SpringContextUtil.getBean(RefreshChattingRedisMQConsumer.class).initBean();
        SpringContextUtil.getBean(PersistentMessageRedisMQConsumer.class).initBean();
        SpringContextUtil.getBean(MomentPublishRedisMQConsumer.class).initBean();
        new Thread(() -> SpringContextUtil.getBean(MallProductOrderTimeoutDelayRedisMQConsumer.class).schedule()).start();
        new Thread(() -> SpringContextUtil.getBean(MallProductOrderTimeoutRedisQueueConsumer.class).schedule()).start();
        new Thread(() -> SpringContextUtil.getBean(MallProductOrderTimeoutRedisQueueConsumer.class).schedule()).start();
        new Thread(() -> SpringContextUtil.getBean(MallUserCartRedisQueueConsumer.class).schedule()).start();
    }

}
